package ar.com.larreta.persistencia;

import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.SimpleExpression;

import com.extjs.gxt.ui.client.data.BaseDateFilterConfig;
import com.extjs.gxt.ui.client.data.BaseFilterConfig;

public class AdaptadorBaseDateFilterConfig implements AdaptadorFiltros {
	
	public static String AFTER = "AFTER";
	public static String BEFORE = "BEFORE";
	public static String EQUAL = "EQUAL";
	

	public SimpleExpression obtenerRestriccion(BaseFilterConfig filterConfig) {
		BaseDateFilterConfig dateFilterConfig = (BaseDateFilterConfig) filterConfig;
		if (AFTER.equalsIgnoreCase(dateFilterConfig.getComparison())){
			return Restrictions.lt(filterConfig.getField(), filterConfig.getValue());	
		}
		if (BEFORE.equalsIgnoreCase(dateFilterConfig.getComparison())){
			return Restrictions.gt(filterConfig.getField(), filterConfig.getValue());
		}
		if (EQUAL.equalsIgnoreCase(dateFilterConfig.getComparison())){
			return Restrictions.eq(filterConfig.getField(), filterConfig.getValue());
		}
		return null;
	}

}
